<template>
	<view class="orders">
		<scroll-view class="scroll-view_H" scroll-x="true">
			<view class="slide_type_list">
				<view class="slide_type_list_view" v-for="(item,index) in typeList" :key="index"
					:class="{is_selected:active==index}" @click="changeType(item,index)">
					<view>{{item.name}}</view>
				</view>
			</view>
		</scroll-view>
		<view class="orderlists">
		<view class="content" v-for="(item,index) in orderList" :key="index" @click="goShopDetail(item)">
			<view class="shops">
				<image class="shop_img" :src="item.goods_cover"></image>
				<view class="shops_right">
					<view class="name">{{item.goods_name}}</view>
					<view class="infos">
						<view class="price_msg">
							<view>
								拼购价:
								<text class="price">￥{{item.buy_price}}</text>
							</view>
							<view class="redprice" v-if="type == 3">
								红包:
								<text class="price">￥{{item.lose_red_package}}</text>
							</view>
						</view>
						<text class="people" v-if="type == 1">满员：{{item.join_number}}/{{item.people_number}}人</text>
					</view>
					<view class="create_time">
						<text>{{item.create_date}}</text>
						<button type="default" size="mini" class="apply_btn"
							:class="{'complete_btn':type == 2,'nothas_btn':type == 3}">{{orderType[type].title}}</button>
					</view>
				</view>
			</view>
		</view>
		</view>

		<view v-show="isLoadMore && orderList.length >0">
			<uni-load-more :status="loadStatus"></uni-load-more>
		</view>

		<view class="nodata" v-if="orderList.length == 0">
			<image class="empty_img" :src="IMGLink+'/my/empty.png'" mode="widthFix"></image>
			<view>没有你想要的内容</view>
		</view>

		<view class="cancle_btn" @click="goCancelList">
			<text>取消</text>
			<text>拼购</text>
		</view>
	</view>
</template>

<script>
	import {
		grouplist
	} from '../../../api/my/my.js';
	export default {
		data() {
			return {
				IMGLink: this.IMGLink,
				active: 0,
				typeList: [{
					name: '已报名'
				}, {
					name: '已拼得'
				}, {
					name: '未拼得'
				}],
				orderList: [],
				orderType: {
					1: {
						title: "已报名",
					},
					2: {
						title: "已拼得",
					},
					3: {
						title: "未拼得",
					}
				},
				page: 1, //页码
				size: '10',
				type: "1",
				loadStatus: 'loading', //加载样式：more-加载前样式，loading-加载中样式，nomore-没有数据样式
				isLoadMore: false, //是否加载中
				refresh: false, // 下拉刷新标示
			}
		},
		onLoad() {
			this.getDataList();
		},
		methods: {
			// 列表
			getDataList() {
				uni.showLoading({
					title: '加载中'
				});
				grouplist('userGroupInfo', {
					page: this.page,
					page_size: this.size,
					type: this.type
				}).then(res => {
					let datas = res.data.list;
					this.orderList = this.page == 1 ? datas : this.orderList.concat(datas);
					if (datas.length < this.size) { //小于size数，停止请求
						this.isLoadMore = true;
						this.loadStatus = 'nomore';
					} else {
						this.isLoadMore = false;
					}
					uni.hideLoading();
					if (this.refresh) {
						uni.stopPullDownRefresh();
						this.refresh = false;
					}
				}).catch(error => {
					uni.hideLoading();
					this.isLoadMore = false;
				})
			},
			changeType(item, index) {
				this.active = index;
				this.type = Number(index) + 1;

				this.page = 1;
				this.getDataList();
			},
			onPullDownRefresh() {
				this.page = 1;
				this.getDataList();
				this.refresh = true;
			},
			onReachBottom() {
				if (!this.isLoadMore) { //此处判断，上锁，防止重复请求
					this.isLoadMore = true;
					this.page++;
					this.getDataList();
				}
			},
			// 取消拼购
			goCancelList() {
				uni.navigateTo({
					url: `/pagesA/my/groupbuylist/canclelist`
				})
			},
			goShopDetail(item) {
				uni.navigateTo({
					url: `/pages/shopping/commodity/detail/index?id=${encodeURIComponent(item.goods_id)}&group_id=${item.group_id}&group_type=2`
				})
			}
		}
	}
</script>
<style>
	page {
		background-color: #EFF0F1;
	}
</style>
<style lang="scss" scoped>
	@import "../my.scss";

	// 横向滑动tab
	.scroll-view_H {
		position: fixed;
		left: 0;
		right: 0;
		top: 80rpx;
		/* #ifdef MP-WEIXIN */
		top: 0;
		/* #endif */
		z-index: 11;
		background-color: #FFFFFF;

		.slide_type_list {
			display: flex;
			padding: 20upx 30upx;

			.slide_type_list_view {
				width: 33.3%;
				padding-bottom: 10rpx;
				font-size: 28rpx;
				color: #0B0B0D;
				margin-right: 30rpx;

				view {
					text-align: center;
				}
			}

			.is_selected {
				color: #F54642;
				font-weight: 500;
				position: relative;
			}

			.is_selected:before {
				content: '';
				position: absolute;
				width: 44rpx;
				height: 8rpx;
				left: 50%;
				margin-left: -24rpx;
				bottom: -14rpx;
				background-color: #F54642;
			}
		}
	}

	.content {
		@include cards;
		background-color: #FFFFFF;
		padding: 20rpx 24rpx;
		margin: 30rpx 3% 20rpx;
		font-size: 24rpx;
		color: #0A0C0D;

		.shops {
			@include flexLayout(center, space-between);
			padding: 14rpx 0 30rpx;

			.shop_img {
				width: 138rpx;
				height: 166rpx;
				border-radius: 12rpx;
			}

			&_right {
				width: 75%;
				height: 176rpx;
				@include flexLayout(flex-start, space-between);
				flex-direction: column;

				.name {
					@include exceedFlow(2);
				}

				.infos {
					width: 100%;
					@include flexLayout(center, space-between);
					color: #0B0B0D;
					font-size: 28rpx;
					margin: 10rpx 0;

					.price {
						color: #F54642;
					}

					.people {
						color: #8B8C8D;
						font-size: 20rpx;
					}

					.price_msg {
						@include flexLayout(center, flex-start);
						color: #4C4C4C;

						.redprice {
							margin-left: 20rpx;
						}
					}
				}

				.create_time {
					width: 100%;
					@include flexLayout(center, space-between);
					color: #868686;

					.apply_btn {
						width: 134rpx;
						height: 50rpx;
						line-height: 50rpx;
						background: #F54642;
						color: #FFFFFF;
						border-radius: 44rpx;
						opacity: 0.58;
						margin: 0;
						padding: 0;
					}

					.complete_btn,
					.nothas_btn {
						opacity: 1;
						background-color: #FFFFFF;
					}

					.complete_btn {
						color: #FF0025;
						border: 2rpx solid #FF0025;
					}

					.nothas_btn {
						color: #A7A7A7;
						border: 2rpx solid #A7A7A7;
					}
				}
			}
		}
	}

	.orderlists{
		margin-top: 120rpx;
	}
	.cancle_btn {
		position: fixed;
		right: 30rpx;
		top: 50%;
		width: 104rpx;
		height: 104rpx;
		background: #FFFFFF;
		border: 2rpx solid #F54642;
		border-radius: 50%;
		color: #F54642;
		font-size: 24rpx;
		@include flexLayout(center, center);
		flex-direction: column;
	}

	.nodata {
		text-align: center;
		color: #7D7D7D;
		font-size: 24rpx;
		margin-top: 50%;

		.empty_img {
			width: 468rpx;
		}
	}
</style>
